package com.submit.demo.service.impl;

import com.submit.demo.service.ValidateCodeGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Random;

@Service
public class SmsCodeGenerator implements ValidateCodeGenerator {
    private static final Logger LOGGER = LoggerFactory.getLogger(SmsCodeGenerator.class);
    @Override
    public String generate(HttpSession session) {
        String code = String.valueOf(new Random().nextInt(899999) + 100000);
        session.setAttribute("code", code);
        LOGGER.info("{}：设置短信验证码：{}", session.getId(), code);
        return code;
    }
}
